﻿using CommunityToolkit.Maui;
using ZiChen.SoXunLeiPan.Config;
using ZiChen.SoXunLeiPan.Service;
using ZiChen.SoXunLeiPan.ViewModel.View;
using ZiChen.SoXunLeiPan.Views;

namespace ZiChen.SoXunLeiPan
{
    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .UseMauiCommunityToolkit()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("iconfont.ttf", "IconFont");
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                });
            builder.Services.AddHttpClient("ApiClient", client =>
            {
                client.BaseAddress = new Uri(AppConfig.ApiBaseUrl);
                client.Timeout = TimeSpan.FromSeconds(AppConfig.TimeoutSeconds);
            });
            builder.Services.AddScoped<IHttpService, HttpService>();
            builder.Services.AddTransient<HomeView>();
            builder.Services.AddTransient<ResourceViewModel>();
            builder.Services.AddTransient<DetailsView>();
            builder.Services.AddTransient<DetailsViewModel>();
            builder.Services.AddTransient<SearchView>();
            builder.Services.AddTransient<SearchViewModel>();
            var app = builder.Build();
            App.Services = app.Services;
            return app;
        }
    }
}
